import AcmeLogo from '@/app/ui/acme-logo';
import LoginForm from '@/app/ui/login-form';
import { auth, signIn, signOut } from "@/auth";
import Link from 'next/link';
import { Button } from "@/app/ui/button";

function SignInWithGithub() {
    return (
        <form
            action={async () => {
                "use server";
                await signIn("github", { redirectTo: '/user' });
            }}
        >
            <Button type="submit">使用GitHub登录</Button>
        </form>
    );
}

function SignInWithGitee() {
    return (
        <form
            action={async () => {
                "use server";
                await signIn("gitee", { redirectTo: '/user' });
            }}
        >
            <Button type="submit">使用Gitee登录</Button>
        </form>
    );
}


export default function LoginPage() {
    return (
        <main className="flex items-center justify-center md:h-screen">
            <div className="relative mx-auto flex w-full max-w-[400px] flex-col space-y-2.5 p-4 md:-mt-32">
                <div className="flex h-20 w-full items-end rounded-lg bg-blue-500 p-3 md:h-36">
                    <div className="w-32 text-white md:w-36">
                        <AcmeLogo />
                    </div>
                </div>
                <LoginForm />
                <Link
                    href="/register"
                    className="mt-4 rounded-md bg-blue-500 px-4 py-2 text-sm text-white transition-colors hover:bg-blue-400"
                >
                    注册新用户
                </Link>
                <SignInWithGithub />
                <SignInWithGitee />
            </div>
        </main>
    );
}
